package com.avic.rong.course.activity.otherActivity;

import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.course.showapi.PeiXunBaoMingApi;
import com.avic.rong.utils.ConstantsUtils;
import com.avic.rong.utils.DateUtils;
import com.avic.rong.utils.ToastTools;
import com.avic.rong.wedgit.StringUtil;
import com.example.minato.minastore.BaseResultEntity;
import com.example.minato.minastore.http.HttpManager;
import com.example.minato.minastore.listener.HttpOnNextListener;
import com.example.minato.minastore.utils.CircleProgressDialog;
import com.orhanobut.logger.Logger;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PeiXunBaoMingActivity extends BaseActivity {



    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.ll_root)
    LinearLayout llRoot;
    @BindView(R.id.baoming_name)
    EditText baomingName;
    @BindView(R.id.baoming_contact_way)
    EditText baomingContactWay;
    @BindView(R.id.baoming_fankui)
    EditText baomingFankui;
    @BindView(R.id.tv_tip)
    TextView tv_tip;


    @Override
    protected int getContentViewId() {
        return R.layout.activity_pei_xun_bao_ming;
    }

    @Override
    protected void initView() {

        ButterKnife.bind(this);
        ivRight.setImageResource(R.mipmap.slh);
        tvTitle.setText("报名咨询");
        tv_tip.setText(Html.fromHtml("我们会在1个工作日内和您联系，您也可以致电我们的客服<font color=\"#98C727\">4006-618-301</font>"));

    }



    @OnClick(R.id.iv_back)
    public void goBack(View view) {
        onBackPressed();
    }


    @OnClick(R.id.iv_right)
    public void goDirect(View view) {
        showPopup(PeiXunBaoMingActivity.this, llRoot);
    }


    @OnClick(R.id.baoming_commit)
    public void commit(View view) {

        if (DateUtils.isFastDoubleClick()) return;

        String name = baomingName.getEditableText().toString().trim();
        String contactWay = baomingContactWay.getEditableText().toString().trim();
        String fankui = baomingFankui.getEditableText().toString().trim();
        if (StringUtil.isEmpty(name)){
            ToastTools.showToast("联系人信息不能为空");
            return;
        }
        if (StringUtil.isEmpty(contactWay)){
            ToastTools.showToast("联系方式不能为空");
            return;
        }
        if (StringUtil.isEmpty(fankui)){
            ToastTools.showToast("反馈建议不能为空");
            return;
        }
        Logger.e(TAG, "commit: name:"+name+"  contactway:"+contactWay+"  fankui:" +fankui);
//        CircleProgressDialog.showDialog(PeiXunBaoMingActivity.this);
        PeiXunBaoMingApi peiXunBaoMingApi = new PeiXunBaoMingApi(this, simpleOnNextListener);
        peiXunBaoMingApi.setModel(name,contactWay,fankui);
        peiXunBaoMingApi.setCache(false);
        HttpManager.getInstance().doHttpDeal(peiXunBaoMingApi);
    }

    //提交报名咨询数据监听
    HttpOnNextListener simpleOnNextListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            CircleProgressDialog.closeDialog();
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(PeiXunBaoMingActivity.this, subjects.getMsg());
                return;
            }
            ToastTools.showToast(PeiXunBaoMingActivity.this,"提交成功！");
            finish();
        }


        @Override
        public void onError(final Throwable e) {
            CircleProgressDialog.closeDialog();
            Logger.e("cjx", "培训课时目录列表数据：" + e.getMessage());
        }
    };




    @Override
    protected void addListener() {

    }
}
